package com.bnz.user.controller;

import com.bnz.common.entity.R;
import com.bnz.user.service.SentinelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SentinelController {

    @Autowired
    private SentinelService sentinelService;

    //1. 定义资源方式一：
    @GetMapping("/sentinel/res1")
    public R res1(){
        String info = sentinelService.res1();
        if(info.equals("success")){
            return R.ok();
        }else{
            return R.error().put("message",info);
        }

    }

    //2. 定义资源的方式二：
    @GetMapping("/sentinel/res2")
    public R res2(){
        String info = sentinelService.res2();
        if(info.equals("success")){
            return R.ok();
        }else{
            return R.error(info);
        }
    }

    //3. 异步回调方式
    @GetMapping("/sentinel/res3")
    public R res3(){
        String info = sentinelService.res3();
        if(info.equals("success")){
            return R.ok();
        }else{
            return R.error(info);
        }
    }

    //4. 处理熔断的方式四(@SentinelResource注解)
    @GetMapping("/sentinel/res4")
    public R res4(){
        String info = sentinelService.res4();
        if(info.equals("success")){
            return R.ok();
        }else{
            return R.error(info);
        }
    }
}
